package tenant

import (
	"context"
	"git.mycaigou.com/gfyx/common/rpc_client"
	"git.mycaigou.com/gfyx/micro-gfyx-mp-api/infrastructure/common/constants"
	pb "git.mycaigou.com/gfyx/micro-gfyx-mp-api/proto/micro_gfyx_user_service_proto/micro-gfyx-user-service/tenant"
	"git.myscrm.cn/golang/stark/v4"
)

type tenantsRepository struct {
}

// NewTenantsRepository
// 租户信息
func NewTenantsRepository() TenantsRepositoryIface {
	return &tenantsRepository{}
}

// GetTenantAll 获取所有租户
func (r *tenantsRepository) GetTenantAll(ctx context.Context, request *pb.GetTenantListRequest) (*pb.GetTenantListResponse, error) {
	request.Page = 1
	request.PageSize = 10000
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_USER_SERVICE)
	if err != nil {
		stark.Logger.Errorf(ctx, "GetTenantAll request: %+v, err:%s", request, err.Error())
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()

	client := pb.NewTenantServiceClient(conn)
	res, err := client.GetTenantList(ctx, request)
	if err != nil {
		stark.Logger.Errorf(ctx, "GetTenantAll request: %+v, err:%s", request, err.Error())
		return nil, err
	}
	return res, nil
}
